package com.bitdf.txing.search.config;

import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;

/**
 * @author Lizhiwei
 * @date 2022/9/6 18:55:59
 * 注释：
 */
@Configuration
public class SearchRedisConfig {
    @Bean
    @ConditionalOnProperty(value = "tx.deploy.mode", havingValue = "cloud")
    public RedisSerializer<Object> springSessionDefaultRedisSerializer(){
        return new GenericJackson2JsonRedisSerializer();

    }

    /**
     * 布隆过滤器
     * @param redissonClient
     * @return
     */
    @Bean
    public RBloomFilter<Long> bloomFilter(RedissonClient redissonClient) {
        RBloomFilter<Long> bloomFilter = redissonClient.getBloomFilter("tx-bloom-filter");
        // 预计插入10000个元素  误判率要求为 0.01
        bloomFilter.tryInit(100000, 0.01);
        return bloomFilter;
    }


}
